ColdFusion Article

Flash Metrics Application: A Flash Front End to the ColdFusion GetMetricData Function

Monitoring ColdFusion server metrics is invaluable when developing Internet applications. By observing the metric data, you can identify bottlenecks in the application and find other problem areas. Developers spend hours in front of these tools for the sole purpose of making their applications more efficient and error-free. Having a tool that is simple to operate and easy to understand is key to making this work.

Flash Metrics Application meets these basic application features by keeping the setup steps to a minimum and displaying the data in an easy-to-read grid pattern to give a high-level view of what is going on with the ColdFusion server (see Figure 1).

Flash Metrics Application

Figure 1. Flash Metrics Application

Installing Flash Metrics Application

To install Flash Metrics Application, you need to set up your ColdFusion server, install the necessary files, and then check the installation.

Server Setup

Flash Metrics Application relies heavily on the GetMetricData function. The ColdFusion server requires you to click the Enable CFSTAT option on the Debugging Settings page in the ColdFusion Administrator.

Now restart the ColdFusion server.

Note: The GetMetricData function does not run on Mac OS X.

File Installation

Four files are required to install the application on the server. Install the following files on your ColdFusion server, where appropriate, under the server's web root:

  • Metrics.html: HTML page to hold the Flash Metrics Application SWF file
  • Metrics.swf: Flash portion of the application.
  • CFC/Metrics.cfc: Web service ColdFusion component that returns the result from the GetMetricData function
  • CFC/PerformanceMonitor.cfc: Defines the PerformanceMonitor object

Checking the Installation

To verify that the components are installed correctly, open a browser and navigate to the Metrics.cfc component, adding the ?WSDL attribute to the end of the URL, as follows:

http://127.0.0.1/metrics/CFC/Metrics.cfc?WSDL

The resulting page should look something like Figure 2.

Viewing the source code of the WSDL

Figure 2. Viewing the source code of the WSDL

Note: If your browser returns a blank document, view the HTML source code to see the WSDL.

Operating Flash Metrics Application

Open a browser and navigate to the Metrics.html page. The URL should look similar to the following:

http://127.0.0.1/metrics/Metrics.html

Flash Metrics Application requires a URL pointing to Metrics.cfc. You need to enter this only once. From that point onward, the URL is saved on the client machine using a shared object (which is much like a cookie). Here is an example of what the URL should look like:

Note: Make sure you add ?WSDL at the end of the URL.

Operating the Application

There are only three steps you need to follow to begin a Flash Metrics Application session:

  1. Set the interval which sets the amount of seconds between calls to the server:

  2. Select which attribute of the performance monitor to view:

  3. Click the Get Metrics button:

Viewing the Data

Flash Metrics Application polls the GetMetricData function and requests the performance monitor data. The performance monitor returns a set of attributes describing the ColdFusion server:

  • InstanceName: The name of the ColdFusion server. Default is cfserver.
  • PageHits: Number of HTTP requests received since the ColdFusion server started.
  • ReqQueued: Number of HTTP requests in the staging queue waiting for processing.
  • DBHits: Number of database requests since the server started.
  • ReqRunning: Number of HTTP requests currently running. In the ColdFusion Administrator, you can set the maximum number of requests that run concurrently.
  • ReqTimedOut: Number of HTTP requests that timed out while in the staging queue or during processing.
  • BytesIn: Number of bytes in HTTP requests to the ColdFusion server.
  • BytesOut: Number of bytes in HTTP responses from the ColdFusion server.
  • AvgQueueTime: For the last two HTTP requests (current and previous), the average length of time the request waited in the staging queue.
  • AvgReqTime: For the last two HTTP requests (current and previous), the average length of time the server required to process the request
  • AvgDBTime: For the last two HTTP requests (current and previous), the average length of time the server took to process CFQueries in the request.

As the application runs, you can select different attributes of the performance monitor to view. By selecting different views, the grid changes dynamically.

Be aware that depending on the amount of viewable units, the unit or "dot" size changes in size. That is, if there are only 10 "dots" viewable, the size of the grid becomes larger, then shrinks down when columns in the grid contain more values. During a session, the grid may expand and shrink dynamically throughout the session.

Displaying Column Data

To find out the column amount, and to display additional data, mouse over a column. A data display appears in the upper left corner, showing the performance monitor data:

A bubble also displays the column value:

Another handy feature is to leave the mouse over one column while the grid changes; as that column receives new values, the display updates automatically.

Flash Metrics Application Architecture

Flash Metrics Application Architecture consists of two main parts: a Flash front end and a ColdFusion web service. The Flash front end is responsible for displaying and requesting the Performance Monitor data generated by the GetMetricData function called within the Metrics.cfc web service component. This data is controlled by polling the data in intervals and then is viewed visually within a display and grid.

ColdFusion Web Service

Two components are defined on the server: Metrics.cfc (acts as the web service to the Flash front end) and PerformanceMonitor.cfc (defines the object returned by the Metrics.cfc web service).

When you look into Metrics.cfc you will see only one method, getServerMetrics, which calls the GetMetricData, creates a PerformanceMonitor object with that data, and returns that PerformanceMonitor object. Although it was not entirely necessary to create a definition for PerformanceMonitor, because it is identical to the object returned by the GetMetricData call, we felt it was necessary to define an object that describes the returned value to allow the WSDL to be more descriptive. This way, using tools like DataBinding in Flash becomes much easier.

Flash Front End

We developed the Flash front end using the Model-View-Controller pattern. The code is heavily documented, so we give only a high-level overview here.

The source files for the Flash application include the following:

  • Metrics.flp: Project file that keeps track of all the project files
  • Metrics.fla: Flash application file
  • Metrics.html: File produced when the Flash application is published; it holds the compiled SWF
  • Metrics.swf: File produced when the Flash application is published; this is the final complied product
  • External ActionScript files:

    • com.macromedia.drk7.metrics.forms.ApplicationForm
    • com.macromedia.drk7.metrics.symbols.DataDisplaySymbol
    • com.macromedia.drk7.metrics.symbols.GridColumnSymbol
    • com.macromedia.drk7.metrics.symbols.MetricsGridSymbol
    • com.macromedia.drk7.metrics.symbols.ShapeSymbol
    • com.macromedia.drk7.metrics.symbols.TipSymbol

All written code has been developed using external ActionScript files and has been broken down into two packages: one for Form objects and one for Symbol objects:

  • com.macromedia.drk7.metrics.forms
  • com.macromedia.drk7.metrics.symbols

As you look at Metrics.fla, you will see that ApplicationForm acts as the controller by marshalling data back and forth from the Metrics web service and communicating with the grid, display, and input components. ApplicationForm continues its role as the controller by listening to the events raised by the Model (web service) and the View (grid/display/input) and pushing the new information to the application components that need it.

This flow of the application can be broken down into four major features of the application:

  • User input/control
  • Local storage
  • Grid display
  • Data display

User Input/Control and Local Storage

The very first time the application starts, the user need to enter a URL to Metrics.cfc, so an example of the URL is preloaded. However, if this is not the first time the application starts, and an example has been stored, retrieve that value and store it. All of this is done within the onLoad event in ApplicationForm:

serviceSO = SharedObject.getLocal("com.macromedia.DRK7.metrics"); // get/create shared object that stores the service URL
      
      if(serviceSO.data.url == undefined) {
         // service URL has not been stored yet, so display this as an example
         serviceUrlInput.text = "http://127.0.0.1/macromedia/DRK7/CFC/Metrics.cfc?wsdl"
      } else {
         // retrieve and display store service URL
         serviceUrlInput.text = serviceSO.data.url;
      }

You can see that when a new service connection is attempted within the startInterval() function, this value is stored:

// store the value from serviceUrlInput to be used the next time the app is loaded on the clients machine 
         serviceSO.data.url = serviceUrlInput.text;
         serviceSO.flush();

Interval

The next required user input is the interval time. This numeric number represents the amount, in seconds, to space between the calls to the web service. This value is used by the setInterval function:

var interval:Number = (intervalInput.text * 1000); // times by 1000 to produce seconds
      intervalId = setInterval(obj, "requestServerMetrics", interval, "test");

The setInterval function is a built-in Flash function that calls a user-defined functioned based on an interval in milliseconds.

View

The view input is a ComboBox that notifies the grid to display the values of the selected property. The value of this selected item is used within the showServerMetrics function and as a reference to a property of the PerformanceMonitor object.

Get Metrics Button

This button starts and stops the interval session.

Grid Display

The grid display is a 125 by 75 dot grid. As results are received from the server, they are looped through to populate the grid. To make this more efficient, a counter ensures that only "viewable" records are looped through:

for(var i = startIndex; i < metricsLen; i++) {
   ...
}

One neat feature of this grid is that it scales to show larger or smaller dots to illustrate large or small changes in values. If the grid is humming along between 6 and 9 dots and then jumps to 25, the grid dots scale to a smaller diameter so they can fit more dots in the grid—instead of continually showing the grid at its smallest dot size. (If the application were designed that way, there would not be as noticeable a change.) This feature is accomplished by setting a mask over the grid that fits the display screen and then adjusting the grid's _xscale and _yscale properties. This way, even though the grid changes its appearance, for the most part the application does not know anything has changed.

Each column has a range of 1 to 75 dots. If that range exceeds 75, the value is divided by 75 and then displayed. See showServerMetrics in ApplicationForm.as:

if(val > 75) {
val = val / 75;
}
val = Math.round(val);

Data Display

As you mouse over columns in the grid, an event is raised to ApplicationForm, which then requests the data display to show the PerformanceMonitor object for that column. The data display loops through the properties and values of the PerformanceMonitor object and finally displays them.